package com.edais.service.imp;

import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.edais.dao.InvitationCodeRecordDao;
import com.edais.domain.InvitationCodeRecord;
import com.edais.service.InvitationCodeRecordService;

@Service

public class InvitationCodeRecordServiceImp  implements InvitationCodeRecordService {
	private static final Log logger = LogFactory.getLog(InvitationCodeRecordServiceImp.class);

	@Autowired
	private InvitationCodeRecordDao invitationCodeRecordDao;

	@Override
	public void insertInvitationCodeRecord(InvitationCodeRecord invitationCodeRecord) throws Exception {
		// TODO Auto-generated method stub
		invitationCodeRecordDao.insertInvitationCodeRecord(invitationCodeRecord);
	}
	
	/**
	 * 保存邀请码
	 */
	@Override
	@Transactional
	public void saveInvitationRecord(Map<String,Object> map) throws Exception{
		if(map == null || map.size() == 0){
			return;
		}
		InvitationCodeRecord invitationCodeRecord = new InvitationCodeRecord();
		invitationCodeRecord.setUser_id(Integer.parseInt(map.get("userId").toString()));
		invitationCodeRecord.setInvitation_code(map.get("invitationCode").toString().toUpperCase());
		invitationCodeRecord.setType(map.get("type").toString());//类型（1、注册；2、购买）
		invitationCodeRecord.setOrder_id(Integer.parseInt(map.get("buyOrderId").toString()));
		invitationCodeRecord.setProduct_type( map.get("planId").toString());//产品类型（101，102，103....)
		invitationCodeRecord.setCreate_per(map.get("userId").toString());
		//是否首次购买(0：非首次购买；1：首次购买)
		invitationCodeRecord.setFirst_timetobuy(map.get("firstTimetobuy").toString());
		
		//保存邀请码记录信息
		invitationCodeRecordDao.insertInvitationCodeRecord(invitationCodeRecord);
	}
}
